Simple IO

Standard Input (keyboard) and Standard Output (screen/monitor)

read (*,*) list of variables
write (*,*) list of variables

or

print *, list of variables

Examples

Get input from user, compute result, and display to user.

write(*,*) 'Enter your height (m) and weight (kg)'
read(*,*) ht,wt
write(*,*) 'BMI is ', wt/ht**2
write (*,*) 'Enter the radius of a circle'
read (*,*) r
pi = 3.1415927
write (*,*) 'Area is ', pi*r**2
write (*,*) 'Circumference is ', pi*r**2

Formatted Output

With the addition of a format line, you can format numbers in a variety of ways. In this example, the format line labelled 100 says, print a character string (A) followed by a 3 digit Integer, followed by another character string, followed by 6 character floating point value with 1 digit past the decimal point. The format line labelled 200 says, print a character string (A) followed by a 8 character floating point value with 2 digits past the decimal point.

write (*,*) 'Enter the radius of a circle'
read (*,*) r
pi = 3.1415927
write (*,100) 'Circ of circle with r=', r, ' is ', pi*r**2
write (*,200) 'Area is ', pi*r**2
100 format (A, I3, A, F6.1)
200 format (A, F8.2)

Format Codes

The format of numbers are usually described using either nIw or nFw.d, where:
n is the number of this type of value in the list
I means Integer
F means Floating point value
w is the total number of characters (width) including the decimal point
d is the total number of digits to right of decimal point

Other formatting codes that are available are:

AText string
DDouble precision, exponential notation
ESingle precision, exponential notation
FFloating point value
IInteger
XHorizonal skip (space character)
/Vertical skip (new line)